package bold.module.thrift.client;

import bold.module.thrift.genapi.User;
import bold.module.thrift.genapi.UserI;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import java.util.Arrays;

class Client {

    /**
     * 客户端
     * cmd 执行 语句  thrift.exe  –gen java xxxx.thrift
     */
    public static void main(String[] args) throws TException {

        // 设置调用的服务地址为本地，端口为 7911
        TTransport transport = new TSocket("localhost", 7911);
        transport.open();
        // 设置传输协议为 TBinaryProtocol
        TProtocol protocol = new TBinaryProtocol(transport);

        UserI.Client userI = new UserI.Client(protocol);

        User user = new User();

        user.setAge(Short.valueOf(String.valueOf(12)));
        user.setName("名字");
        user.setCourse(Arrays.asList("课程1", "课程2", "课程3"));


        userI.getList(user);
        userI.getName(user);
        userI.isNan(user);

        transport.close();
    }

}
